package com.twu.biblioteca.db;

import com.twu.biblioteca.models.Book;
import com.twu.biblioteca.models.Movie;
import com.twu.biblioteca.models.User;

import java.util.ArrayList;
import java.util.List;

public class Database {
    private List<Book> books = books = new ArrayList<Book>();
    private List<Movie> movies = movies = new ArrayList<Movie>();
    private List<User> users = users = new ArrayList<User>();

    public void init() {
        books.add(new Book(1, "The Lord of the Rings - The Fellowship of the Ring"));
        books.add(new Book(2, "The Lord of the Rings - The Two Towers"));
        books.add(new Book(3, "The Lord of the Rings - The Return of the King"));

        movies.add(new Movie("Sholay", 1975, "Ramesh Sippy", "N/A"));
        movies.add(new Movie("Movie2", 2001, "Rohit Shetty", "5"));
        movies.add(new Movie("Movie3", 2001, "Homi Adajania", "6"));
        movies.add(new Movie("Movie4", 1986, "Ramesh Sippy", "4"));
        movies.add(new Movie("Movie5", 2013, "Homi Adajania", "7"));
        movies.add(new Movie("Movie6", 2013, "Ramesh Sippy", "7"));
        movies.add(new Movie("Movie7", 2005, "Ramesh Sippy", "8"));
        movies.add(new Movie("Movie8", 1989, "Homi Adajania", "N/A"));
        movies.add(new Movie("Movie9", 2003, "Homi Adajania", "4"));
        movies.add(new Movie("Movie10", 1999, "Ramesh Sippy", "4"));
        movies.add(new Movie("Movie11", 2009, "Rohit Shetty", "9"));
        movies.add(new Movie("Movie12", 1975, "Rohit Shetty", "5"));
        movies.add(new Movie("Movie13", 2012, "Ramesh Sippy", "6"));
        movies.add(new Movie("Movie14", 2011, "Rohit Shetty", "N/A"));
        movies.add(new Movie("Movie15", 2013, "Rohit Shetty", "N/A"));

        users.add(new User("111-1111", "luan@123", "Luan", "luan@library.com", "8888-8888"));
        users.add(new User("111-1112", "rodrigo@123", "Rodrigo", "rodrigo@library.com", "9999-9999"));
    }

    public void initWithValues(List<Book> books, List<Movie> movies, List<User> users) {
        this.books = books;
        this.movies = movies;
        this.users = users;
    }

    public User getUserByLogin(String login) {
        for (User user : users) {
            if (user.getLogin().equals(login))
                return user;
        }
        return null;
    }

    public Book getBookById(int id) {
        for (Book book : books) {
            if (book.getId() == id)
                return book;
        }
        return null;
    }

    public List<Book> getAllBooks() {
        return books;
    }

    public List<Movie> getAllMovies() {
        return movies;
    }
}